package com.jinbei.restController;

import com.jinbei.common.annotation.AuthorAnnotation;
import com.jinbei.common.base.ResponseBase;
import com.jinbei.common.base.ResponseBaseEntity;
import com.jinbei.common.contants.Contants;
import com.jinbei.service.KvbSendMsgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * kvb发送短信controller
 * Created by lucky on 2018/10/9.
 */
@RestController
@RequestMapping("/kvb")
public class KvbSendMsgController {

    private Logger logger = LoggerFactory.getLogger(KvbSendMsgController.class);

    @Autowired
    private KvbSendMsgService kvbSendMsgService;

    /**
     * @author zflu
     * @Description   kvb短信发送
     * @date 2018/10/9 15:03
     * @param file
     * @return com.jinbei.common.base.ResponseBase
     */
    @AuthorAnnotation(name ="/kvb/sendMessageToKvb" , logs = "kvb短信发送")
    @PostMapping("/sendMessageToKvb")
    public ResponseBase sendMessageToKvb(@RequestParam("file") MultipartFile file){
        try {
            Boolean result = kvbSendMsgService.sendMsgToKvb(file);
            if(result){
                return ResponseBaseEntity.setResultSuccess(Contants.BOOLEAN_TRUE);
            }else{
                return ResponseBaseEntity.setResultSuccess(Contants.BOOLEAN_FALSE);
            }
        }catch (Exception e){
            logger.error("kvb短信发送失败! error: {}",e);
            return ResponseBaseEntity.setResultError(null);
        }
    }
}
